package com.itheima.controller;

import com.itheima.common.PageResult2;
import com.itheima.common.PermissionsGg;
import com.itheima.entity.R4Dto;
import com.itheima.service.PermissionGroupService;
import com.itheima.service.PermissionsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author cfr
 * @date 2022/1/11
 * @TIME:20:49
 */
@RestController
@RequestMapping("/permissions")
public class PermissionsController {
    @Autowired
    private PermissionsService permissionsService;
    @Autowired
    private PermissionGroupService permissionGroupService;

    @DeleteMapping("/{id}")
    public String add(@PathVariable Integer id) {
        return permissionsService.deleteById(id);
    }

    @GetMapping()
    public PageResult2 finfPage(Integer page, Integer pagesize, String title) {
        return permissionsService.findPage(page, pagesize, title);
    }

    @GetMapping("simple")
    public List<R4Dto> simple(){
        return permissionGroupService.simple();
    }

    @PostMapping
    public String add(@RequestBody PermissionsGg permissions) {
        return permissionsService.add(permissions);
    }


    @GetMapping("/{id}")
    public PermissionsGg fingById(@PathVariable Integer id){
        return permissionsService.findById(id);
    }

    @PutMapping("/{id}")
    public String modify(@RequestBody PermissionsGg permissionsGg){
        return permissionsService.modify(permissionsGg);
    }
}
